package com.icoding.trangphuc.admin

import com.icoding.trangphuc.Article
import com.icoding.trangphuc.Category
import com.icoding.trangphuc.constant.CategoryStatus;

class CategoryController {

	def showPageByCategory = {
		def id = params['id']
		if(id=="1"){
			render(view:"/trangphuc/admin/category")
		}
		else if(id=="2"){
			render(view:"/trangphuc/admin/product")
		}
		else if(id=="3"){
			render(view:"trangphuc/admin/news")
		}
	}

	/*def saveCategory ={
		String subject = params['subject']
		String description = params['description']
		Date dateCreated = new Date(params['dateCreated'])
		String metaDescription = params['metaDescription']
		String metaKeyword = params['metaKeyword']

		def article = new Article(subject:subject,description:description,dateCreated:dateCreated,metaDescription:metaDescription,metaKeyword:metaKeyword)
		article.save(flush:true)
		String catStatus = CategoryStatus.ADMIN.getValue()
		Integer parent = null
		def category = new Category(id:article.id,parent:parent,categoryStatus:catStatus)
		category.save(flush:true)
	}*/
	
	def saveCategory ={
		try {
			String subject = "Subject 1"
			String description = "Description 1"
			String metaDescription = "abc"
			String metaKeyword = "bca"
	
			def article = new Article(subject:subject,description:description,metaDescription:metaDescription,metaKeyword:metaKeyword)
			article.save()
			/*String catStatus = CategoryStatus.ADMIN.getValue()
			Integer parent = 1
			def category = new Category(id:article.id,parent:parent,categoryStatus:catStatus)
			category.save()*/
		} catch (Exception e) {
			e.printStackTrace()
		}
		render("success")
	}
}
